home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Maclife 40
/
MACLIFE40.ISO.7z
/
MACLIFE40.ISO
/
MACLIFE連載
/
特集II DTPデザインを効率化
/
AppleScript⁄サンプル
/
SampleScript
/
For OtherApplication
/
平凡な毎日_folder
/
平凡な毎日.src
< prev
Wrap
Text File
|
1998-05-16
|
7KB
|
272 lines
global YOUBI_LIST, FF, ANS, HARU, AKI
with timeout of 3600 seconds
repeat --入力がされるまでくりかえす
set ANS to text returned of (display dialog "カレンダーを作成する場合は西暦年を
曜日が知りたい場合は日付まで入力してください。
ex.) 1998
1998.5.5" default answer "1998" with icon 1)
if ANS is not "" then exit repeat
end repeat
end timeout
try --なにが入力されているかわからないんで
--入力を分割
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set ANS_1 to every text item of ANS
set AppleScript's text item delimiters to TID
--カレンダー作成
if length of (ANS_1) = 1 then
with timeout of 3600 seconds
set new_file to new file with prompt "どこに保存しますか?" default name (ANS as string)
end timeout
--この年は何曜日から始まるのか(システム依存)
set YOUBI to weekday of (date (item 1 of ANS_1 & ".1.1"))
--この年は閏年か?(この計算では、2100年の閏年にならない年を計算できない)
if (ANS mod 4) is 0 then
set URU to true
else
set URU to false
end if
--カレンダーの作成はサブルーチンにおまかせ
set CALENDER to ANS & "年カレンダー" & return & return
set CALENDER to my make_CALENDER(CALENDER, YOUBI, URU)
--ファイル書き込み
set FH to open for access new_file with write permission
try
write CALENDER to FH
on error errMsg number ERRNO
close access FH
display dialog "書き込みエラーが発生しました" & return & errMsg & ERRNO
return
end try
close access FH
display dialog "正常に書き込まれました。
ただし、春分・秋分の日(およびその振替休日)は簡易計算によるものです。正確には前年の2月1日付の官報で決定されますのでそちらも参照してください。" with icon 1
--今日は何の日?データーベース
else if (length of ANS_1) = 2 then
display dialog "今日は何の日?データーベースは次期バージョンでサポートです。ごめんなさい。" with icon 1
--曜日計算(将来的に六曜もサポートしたい...)
else if (length of ANS_1) = 3 then
set YOUBI to weekday of (date ANS) --(システム依存)
set YOUBI to my make_YOUBI(YOUBI)
display dialog ANS & ";" & YOUBI & "曜日" with icon1
--入力違い
else
display dialog "たぶん入力を間違えています。
数字もピリオドも半角で、余分なスペースは入れないでください。" with icon 2
end if
--エラー処理
on error errMsg number ERRNO
display dialog "たぶん入力を間違えています。
数字もピリオドも半角で、余分なスペースは入れないでください。
" & "errNO. " & ERRNO & return & errMsg with icon 2
end try
--●曜日換算
------------------------------------------------------------------------------------
on make_YOUBI(YOUBI)
if YOUBI = Sunday then
set YOUBI to "日"
else if YOUBI = Monday then
set YOUBI to "月"
else if YOUBI = Tuesday then
set YOUBI to "火"
else if YOUBI = Wednesday then
set YOUBI to "水"
else if YOUBI = Thursday then
set YOUBI to "木"
else if YOUBI = Friday then
set YOUBI to "金"
else if YOUBI = Saturday then
set YOUBI to "土"
end if
--これじゃだめじゃった...
--set aa to {Sunday:{1, 日}, Monday:{2, 月}, Tuesday:{3, 火}, Wednesday:{4, 水}, Thursday:{5, 木}, Friday:{6, 金}, Saturday:{7, 土}}
--set YOUBI to item 2 of YOUBI of aa
return YOUBI
end make_YOUBI
--●カレンダー作成
------------------------------------------------------------------------------------
on make_CALENDER(CALENDER, YOUBI, URU)
--元旦の曜日を数字に変換(こんなやり方しかないとは...とほほ)
if YOUBI = Sunday then
set YOUBI to 1
else if YOUBI = Monday then
set YOUBI to 2
else if YOUBI = Tuesday then
set YOUBI to 3
else if YOUBI = Wednesday then
set YOUBI to 4
else if YOUBI = Thursday then
set YOUBI to 5
else if YOUBI = Friday then
set YOUBI to 6
else if YOUBI = Saturday then
set YOUBI to 7
end if
--そいでこのリストと対比させる(グローバル変数)
global YOUBI_LIST
set YOUBI_LIST to {"(日)", "(月)", "(火)", "(水)", "(木)", "(金)", "(土)"}
--春分・秋分の日計算(これはあくまで簡易計算です。しかも1900≦西暦≦2099)
set HARU to (0.24242 * ANS - (ANS div 4) + 35.84) div 1
set AKI to (0.24204 * ANS - (ANS div 4) + 39.01) div 1
--ここから作成(でも実際はKEISAN()が仕事してます)
repeat with TUKI from 1 to 12
if TUKI = 1 or TUKI = 3 or TUKI = 5 or TUKI = 7 or TUKI = 8 or TUKI = 10 or TUKI = 12 then --大の月 31 日まで
repeat with NITI from 1 to 31
set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
set YOUBI to my YOUBI_kasan(YOUBI)
end repeat
else if TUKI = 2 and URU = true then --閏年の2月
repeat with NITI from 1 to 29
set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
set YOUBI to my YOUBI_kasan(YOUBI)
end repeat
else if TUKI = 2 and URU = false then --普通の2月
repeat with NITI from 1 to 28
set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
set YOUBI to my YOUBI_kasan(YOUBI)
end repeat
else if TUKI = 4 or TUKI = 6 or TUKI = 9 or TUKI = 11 then --小の月 30 日まで
repeat with NITI from 1 to 30
set CALENDER to my KEISAN(CALENDER, TUKI, NITI, YOUBI)
set YOUBI to my YOUBI_kasan(YOUBI)
end repeat
end if
end repeat
return CALENDER
end make_CALENDER
--●曜日・祝日・振替えの計算
------------------------------------------------------------------------------------
on KEISAN(CALENDER, TUKI, NITI, YOUBI)
--祝祭日(春分・秋分は簡易計算に基づく)
if TUKI = 1 and NITI = 1 then
set IWAI to "元旦"
set F to 0 --振り替え休日なし
else if TUKI = 1 and NITI = 15 then
set IWAI to "成人の日"
set F to 1 --振り替え休日あり
else if TUKI = 2 and NITI = 11 then
set IWAI to "建国記念日"
set F to 1
else if TUKI = 3 and NITI = HARU then
set IWAI to "春分の日"
set F to 1
else if TUKI = 4 and NITI = 29 then
set IWAI to "緑の日"
set F to 1
else if TUKI = 5 and NITI = 3 then
set IWAI to "憲法記念日"
set F to 1
else if TUKI = 5 and NITI = 5 then
set IWAI to "こどもの日"
set F to 1
else if TUKI = 7 and NITI = 20 then
set IWAI to "海の日"
set F to 1
else if TUKI = 9 and NITI = 15 then
set IWAI to "敬老の日"
set F to 1
else if TUKI = 9 and NITI = AKI then
set IWAI to "秋分の日"
set F to 1
else if TUKI = 10 and NITI = 10 then
set IWAI to "体育の日"
set F to 1
else if TUKI = 11 and NITI = 3 then
set IWAI to "文化の日"
set F to 1
else if TUKI = 11 and NITI = 23 then
set IWAI to "勤労感謝の日"
set F to 1
else if TUKI = 12 and NITI = 23 then
set IWAI to "天皇誕生日"
set F to 1
else
set IWAI to ""
set F to 0
end if
--振り替え休日
global FF
if YOUBI = 1 and F = 1 then --日曜日に休日
set FF to 2
else if YOUBI = 2 and FF = 1 then --その次の日(振り替え)
set IWAI to "振替休日"
else
set FF to 0
end if
--変数CALENDERへの書き込み
set CALENDER to CALENDER & TUKI & "月" & NITI & "日" & item YOUBI of YOUBI_LIST & IWAI & return
--振替休日のフラッグを減じる
set FF to FF - 1
return CALENDER
end KEISAN
--●曜日の加算
------------------------------------------------------------------------------------
on YOUBI_kasan(YOUBI)
--曜日の加算
if YOUBI = 7 then
set YOUBI to YOUBI - 6
else
set YOUBI to YOUBI + 1
end if
return YOUBI
end YOUBI_kasan